home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
326
< prev
next >
Wrap
Internet Message Format
|
1996-08-06
|
4KB
Path: tko.dec.com!diamond
From: diamond@tko.dec.com (Norman Diamond)
Newsgroups: comp.std.c
Subject: Re: Binary Mode stdin/stdout
Date: 8 Feb 1996 02:40:35 GMT
Organization: Digital Equipment Corporation Japan , Tokyo
Message-ID: <4fbnr3$veg@usenet.pa.dec.com>
References: <4f67kg$11g@cortex.dialin.rrze.uni-erlangen.de> <DME74w.4M4@stdc.demon.co.uk>
Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
NNTP-Posting-Host: jit533.tko.dec.com
In article <DME74w.4M4@stdc.demon.co.uk>, clive@stdc.demon.co.uk (Clive D.W. Feather) writes:
>In article <4f67kg$11g@cortex.dialin.rrze.uni-erlangen.de>,
>Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de> wrote:
>> Why isn't there a standard way of allowing an ISO C program to switch
>> the standard input and output into binary transparent mode (as with
>> the "b" flag in fopen()/freopen() for normal files)?
>On some implementations, this decision has to be made at the time you
>open the file and can't be changed.
I'll take your word for it. I suppose the operating system would require
the program to close the file and reopen it, so that is what the C standard
requires the C program to do. (This is also why the C standard requires C
programs to simulate long int arithmetic on their own instead of building
it into the language, since some hardware doesn't have it, right?)
>For example, on OS/360 and its successors, text files might be VB80,
>while binary files will be U508, or whatever. The former is stored as:
> <4 byte value N1> <N1 bytes of text forming a line>
> <4 byte value N2> <N1 bytes of text forming a line>
> <4 byte value N3> <N1 bytes of text forming a line>
Close...
<4 byte block length, max. value 80>
<4 byte value N1> <N1 bytes of text forming a line>
<4 byte value N2> <N2 bytes of text forming a line>
<4 byte value N3> <N3 bytes of text forming a line>
Actually I have a vague recollection that the counts are recorded
as 4+N1, 4+N2, and 4+N3 (i.e. their lengths include themselves).
>(note that there are no newline characters) and the latter as
> <4 byte value N1> <N1 bytes of data> <508-N1 bytes ignored>
> <4 byte value N2> <N1 bytes of data> <508-N1 bytes ignored>
> <4 byte value N3> <N1 bytes of data> <508-N1 bytes ignored>
>(data is read and written in 512 byte units).
Not so close this time. Only the data are recorded, max. 508 bytes per line:
<N1 bytes of data>
<N2 bytes of data>
<N3 bytes of data>
Though again there is no recording of newline characters.
>How do you switch these ?
By storing the desired form of reading into the RECFM field of the DCB
before doing the read. If a file was written using format VB80 and read
back using format VB80 then you see each line as it was written. If a
file was written using format VB80 and read back using format U508 then
you see the actual recorded form of each block, and you get to break it
up yourself or not as you wish. If a file was written using format U508
and read back using format VB80, then either you had to be very careful
to write something that conforms to VB80 or else behavior would probably
be undefined.
However, I'll take your word for it that C has been implemented on less
cooperative operating systems.
--
<< If this were the company's opinion, I would not be allowed to post it. >>
"I paid money for this car, I pay taxes for vehicle registration and a driver's
license, so I can drive in any lane I want, and no innocent victim gets to call
the cops just 'cause the lane's not goin' the same direction as me" - J Spammer